using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using GoChat_for_Windows.ViewModels;
using GoChat_for_Windows.Models;

namespace GoChat_for_Windows.Views
{
    public sealed partial class ChatPage : Page
    {
        public ChatViewModel ViewModel { get; }

        public ChatPage()
        {
            ViewModel = App.GetService<ChatViewModel>();
            this.InitializeComponent();
            DataContext = ViewModel;
        }

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.Parameter is User targetUser)
            {
                await ViewModel.InitializeAsync(targetUser);
            }
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            ViewModel.Cleanup();
        }
    }
} 